﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;

namespace D2DEngine.Core
{
    public class D2DAssetDatabase
    {
        private static D2DAssetDatabase instance = new D2DAssetDatabase();
        Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();
        Dictionary<string, SpriteFont> fonts = new Dictionary<string, SpriteFont>();
        Dictionary<string, SoundEffect> sounds = new Dictionary<string, SoundEffect>();

        /// <summary>
        /// Private constructor
        /// </summary>
        private D2DAssetDatabase()
        {
        }

        /// <summary>
        /// The unique instance of the object database
        /// </summary>
        public static D2DAssetDatabase Instance
        {
            get { return instance; }
        }

        /// <summary>
        /// Retrieves a texture in the bank
        /// </summary>
        /// <typeparam name="T">Texture name</typeparam>
        /// <returns></returns>
        public Texture2D GetTexture(string name)
        {
            return this.textures[name];
        }

        /// <summary>
        /// Retrieves a font in the bank
        /// </summary>
        /// <typeparam name="T">Font name</typeparam>
        /// <returns></returns>
        public SpriteFont GetFont(string name)
        {
            return this.fonts[name];
        }

        /// <summary>
        /// Retrieves a sound in the bank
        /// </summary>
        /// <param name="name">Sound name</param>
        /// <returns></returns>
        public SoundEffect GetSound(string name)
        {
            return this.sounds[name];
        }

        /// <summary>
        /// Adds a texture to the asset database
        /// </summary>
        /// <param name="index"></param>
        /// <param name="texture"></param>
        public void AddTexture(string index, Texture2D texture)
        {
            this.textures.Add(index, texture);
        }

        /// <summary>
        /// Adds a sound to the asset database
        /// </summary>
        /// <param name="index"></param>
        /// <param name="sound"></param>
        public void AddSound(string index, SoundEffect sound)
        {
            this.sounds.Add(index, sound);
        }

        /// <summary>
        /// Adds a font to the asset database
        /// </summary>
        /// <param name="index"></param>
        /// <param name="texture"></param>
        public void AddFont(string index, SpriteFont font)
        {
            this.fonts.Add(index, font);
        }
    }
}
